const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navIndex: 0,
        refund_list: [],
        curpage: 1,
        page: 10,
        reset: true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        var self = this;
        self.setData({
            hasmore: true
        })
        wx.getStorage({
            key: 'key',
            success: res => {
                self.setData({
                    key: res.data
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        this.initPage();

    },
    initPage: function () {
        wx.showLoading()
        if (!this.data.reset) {
            this.setData({
                refund_list: [],
                curpage: 1
            })
        }
        this.setData({
            reset: true
        })
        var self = this;
        var act = '';
        var op = '';
        if (self.data.navIndex == 0) {
            act = 'member_refund';
            op = 'get_refund_list'
        } else if (self.data.navIndex == 1) {
            act = 'member_return';
            op = 'get_return_list'
        }
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=' + act + '&op=' + op,
            data: {
                key: self.data.key,
                page: self.data.page,
                curpage: self.data.curpage,
            },
            method: 'GET',
            dataType: 'json',
            success: res => {
                self.setData({
                    curpage: self.data.curpage + 1
                })
                if (res.data.code == 200) {
                    if (self.data.navIndex == 0) {
                        self.setData({
                            refund_list: self.data.refund_list.concat(res.data.datas.refund_list),
                            hasmore: res.data.hasmore
                        })
                    } else if (self.data.navIndex == 1) {
                        self.setData({
                            return_list: self.data.refund_list.concat(res.data.datas.return_list),
                            hasmore: res.data.hasmore
                        })
                    }

                }
            },
            complete: () => {
                wx.hideLoading()
            }
        })
    },
  preventTouchMove: function () {
    return false;
  },
    changeNav: function (e) {
        var index = e.currentTarget.dataset.index;
        this.setData({
            navIndex: index,
            hasmore: true,
            reset: false
        })
        this.initPage()
    },
    swiperChange: function (e) {
        this.setData({
            navIndex: e.detail.current
        })
    },
    onReachBottom: function () {
        this.initPage()
    }
})